package com.spark.concurrency.thread.method;

import java.time.LocalDateTime;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * wait方法必须包含在synchronized代码块中，否则会报错，
 */
public class WaitTest {
    public static void main(String[] args) {
        System.out.println(LocalDateTime.now());
        Object lock = new Object();
        //Lock l=new ReentrantLock();
        Thread thread = new Thread(() -> {
            synchronized (lock) {
                try {
                    //l.lock();
                    // 1 秒钟之后自动唤醒
                    lock.wait(1000);
                    System.out.println(LocalDateTime.now());

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //finally {
                //l.unlock();
                //}
            }
        });
        thread.start();
    }
}
